using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static WaterCylinder.Object;

public class EnemyCreator : MonoBehaviour
{   
    [Serializable]
    public class EnemyCreateInfo{
        public Enemy enemy;
        public int weight = 10;
    }
    public List<EnemyCreateInfo> createInfos;
    public EnemyContainer Creat(){
        //根据权重生成EnemyContainer并装配对应的Enemy
        int W = 0;
        foreach(var item in createInfos){
            W += item.weight;
        }
        int cW = 0;
        int r = MapController.instance.SeedRandom(1, W+1);
        foreach(var item in createInfos){
            cW += item.weight;
            if(r <= cW){
                return EnemyContainer.CreatEnemy(item.enemy,transform.position);
            }
        }
        return null;
    }
    [Tooltip("是否自动创建")]
    public bool isAuto = true;

    public void Run(){
        Creat();
        Delete(gameObject);
    }

    private void Start() {
        if(isAuto)Run();
    }
}
